package yo.latyoo.hokage.skmr.biz.model;

import jakarta.persistence.Convert;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import yo.latyoo.hokage.tools.expression.enums.ScheduleTypeEnum;
import yo.latyoo.hokage.tools.route.RouteEnum;
import yo.latyoo.hokage.tools.util.db.ListStringConvert;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

public class JobModel implements Serializable {
    public Long id;
    @Convert(converter = ListStringConvert.class)
    public List<String> registryList;  // 执行器的地址
    public String jobDesc;
    //调度方式
    @Enumerated(EnumType.STRING)
    public ScheduleTypeEnum scheduleType;
    //调度表达式
    public String expression;			// 表达式  视ScheduleTypeEnum而定
    public String handlerMethod = "executeJob";		    // 执行器，任务方法名称
    public String handlerParams;		    // 执行器，任务参数
    public int timeout;     		// 任务执行超时时间，单位秒
    public int failRetryCount = 0;		// 失败重试次数
    @Enumerated(EnumType.STRING)
    public RouteEnum routeType = RouteEnum.RANDOM;	//执行器的策略
    public int shardingIndex; //执行器的策略为SHARDING_BROADCAST 有效
    public LocalDateTime nextRunTime;	// 下次调度时间
    public LocalDateTime lastRunTime;

    public JobModel(Long id, List<String> registryList, String jobDesc,
                    ScheduleTypeEnum scheduleType, String expression,
                    String handlerMethod, String handlerParams, int timeout,
                    int failRetryCount, RouteEnum routeType, int shardingIndex,
                    LocalDateTime nextRunTime,LocalDateTime lastRunTime) {
        this.id = id;
        this.registryList = registryList;
        this.jobDesc = jobDesc;
        this.scheduleType = scheduleType;
        this.expression = expression;
        this.handlerMethod = handlerMethod;
        this.handlerParams = handlerParams;
        this.timeout = timeout;
        this.failRetryCount = failRetryCount;
        this.routeType = routeType;
        this.shardingIndex = shardingIndex;
        this.nextRunTime = nextRunTime;
        this.lastRunTime = lastRunTime;
    }

    public JobModel() {
    }
}
